package com.zmn.oms.api.controller.third.suning;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.utils.RequestUtil;
import com.zmn.oms.third.suning.SuningConsts;
import com.zmn.oms.third.suning.dto.SuningRequestBaseDTO;
import com.zmn.oms.third.suning.dto.SuningRequestDTO;
import com.zmn.oms.third.suning.service.SuningService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 类描述：顺丰安装渠道对接接口，用于接受渠道创建和取消订单
 *
 * @author xiewenbing
 * @date 2020/12/11 11:00
 */

@RestController
@RequestMapping("/suning")
@Slf4j
public class SuningController {

    @Autowired
    private SuningService suningService;

    @PostMapping("/api/order")
    public JSONObject handleOrderMsg(HttpServletRequest httpServletRequest, SuningRequestBaseDTO requestBaseDTO) {

        SuningRequestDTO requestDTO = BeanMapper.map(requestBaseDTO,SuningRequestDTO.class);
        requestDTO.setBody(RequestUtil.getPostParameter(httpServletRequest));

        String response = suningService.handleOrderRequest(requestDTO);

        log.info("【{}】收到请求【{}】,返回【{}】",SuningConsts.CHANNEL_NAME,JSON.toJSONString(requestBaseDTO),response);

        return JSON.parseObject(response);
    }
}
